package com.tanhua.server.controller;

import com.tanhua.model.vo.CommentVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 评论管理控制层
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 评论列表查询
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity commentsList(@RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pagesize", defaultValue = "10") Long pagesize, String movementId){
        PageResult<CommentVo> commentVoPageResult = commentsService.commentsList(page,pagesize,movementId);
        return ResponseEntity.ok(commentVoPageResult);
    }

    /**
     * 评论-提交
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity comment(@RequestBody Map<String,String> params){
        String movementId = params.get("movementId");//动态主键id
        String content = params.get("comment");//动态主键id
        commentsService.addComment(movementId,content);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论-点赞
     */
    @RequestMapping(value = "/{commentId}/like",method = RequestMethod.GET)
    public ResponseEntity like(@PathVariable("commentId") String  commentId){

        Integer count = commentsService.like(commentId);

        return ResponseEntity.ok(count);
    }

    /**
     * 评论-点赞取消
     */
    @RequestMapping(value = "/{commentId}/dislike",method = RequestMethod.GET)
    public ResponseEntity dislike(@PathVariable("commentId") String  commentId){

        Integer count = commentsService.dislike(commentId);

        return ResponseEntity.ok(count);
    }
}
